package com.cmbchina.creditcard.domain.model;

import lombok.Data;

import java.math.BigDecimal;
import java.util.Objects;
import java.util.UUID;

/**
 * 信用卡
 */
@Data
public abstract class CreditCard {
    private String id; // 卡号
    private String type; //类型
    private BigDecimal quota; //额度

    public CreditCard(String type, BigDecimal quota) {
        this.type = type;
        this.quota = quota;
        this.id = UUID.randomUUID().toString();
    }

    /**消费*/
    public Boolean consume(BigDecimal amount){
        if(Objects.isNull(amount) || amount.compareTo(BigDecimal.ZERO) < 0 || amount.compareTo(this.quota) > 0){
            return false;
        }else{
            this.quota = this.quota.subtract(amount);
            updatePoints(amount);
            return true;
        }
    }

    /**消费*/
    public Boolean repay(BigDecimal amount){
        if(Objects.isNull(amount) || amount.compareTo(BigDecimal.ZERO) < 0){
            return false;
        }
        this.quota = this.quota.add(amount);
        return true;
    }

    /**更新积分*/
    protected abstract void updatePoints(BigDecimal amount);
}
